<?php
declare(strict_types=1);

namespace App\Controller\WebApi\v1;

use App\Controller\AbstractController;
use Hyperf\HttpServer\Contract\RequestInterface;
use Hyperf\HttpServer\Annotation\RequestMapping;
use Hyperf\HttpServer\Annotation\Controller;
use App\Middleware\WebApiMiddleware;
use Hyperf\HttpServer\Annotation\Middleware;
use Service\MemberService\MemberCommentService;
use Hyperf\Di\Annotation\Inject;

/**
 * 用户评论
 * @author huj
 * @Controller(prefix="/webapi/v1/membercomment")
 * @Middleware(WebApiMiddleware::class)
 */
class MemberCommentController extends AbstractController
{
     /**
     * 通过 `@Inject` 注解注入由 `@var` 注解声明的属性类型对象
     * @Inject()
     * @var MemberCommentService
     */
    protected $memberCommentService;

    /**
     * 我的评价
     * @RequestMapping(path="index", methods="get,post")
     */
    public function index(RequestInterface $request) 
    {
        $param        = $request->inputs(['page', 'limit']);
        $param['mid'] = $request->getAttribute('mid');
        return $this->memberCommentService->getComment($param);
    }

    /**
     * 添加评论
     * @RequestMapping(path="add", methods="get,post")
     */
    public function add(RequestInterface $request)
    {
        $param        = $request->inputs(['attach','goods_common_id','goods_id','content','star','og_id']);
        $param['mid'] = $request->getAttribute('mid');
        return $this->memberCommentService->addComment($param);
    }

    /**
     * 编辑评论
     * @RequestMapping(path="edit", methods="get,post")
     */
    public function edit(RequestInterface $request)
    {
        $param        = $request->inputs(['attach','content','star','id']);
        $param['mid'] = $request->getAttribute('mid');
        return $this->memberCommentService->editComment($param);
    }

    /**
     * 评论回复
     * @RequestMapping(path="reply", methods="get,post")
     */
    public function reply(RequestInterface $request)
    {
        $param        = $request->inputs(['content','pid']);
        $param['mid'] = $request->getAttribute('mid');
        return $this->memberCommentService->replyComment($param);
    }
}